package dao;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import connectUtil.ConnectionUtil;
import entity.Tour;

public class TourDetailDAO {
	private static Connection conn;
    private static CallableStatement callProc;
    private static ResultSet rs;
	public static Tour getTourDetail(int id){
		Tour e = null;
		try{
			conn = ConnectionUtil.getConnection();
    		callProc = conn.prepareCall("{call getTourDetail(?)}");
    		callProc.setInt(1,id);
    		rs = callProc.executeQuery();
    		while(rs.next()){
    			e = new Tour();
    			e.setId(rs.getInt("id"));
    			e.setTourName(rs.getString("tourName"));
    			e.setPlace(rs.getString("place"));
    			e.setStartDate(rs.getDate("startDate"));
    			e.setEndDate(rs.getDate("endDate"));
    			e.setPrice(rs.getFloat("price"));
    			e.setMaxVisitors(rs.getShort("maxVisitors"));
    			e.setCurrentVisitors(rs.getShort("currentVisitors"));
    		}
		}catch(Exception ex){
			System.out.println(ex.getMessage());
		}
		finally{
            ConnectionUtil.closeConnections(conn, callProc, rs);
		}
		return e;
	}
    public static void main(String[] args) {
		System.out.println(getTourDetail(3).getId());
	}
}
